package com.cxria.shiro.repository;

import com.cxria.shiro.entity.Permission;
import com.cxria.shiro.entity.RolePermission;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface RolePermissionRepository extends BaseRepository<RolePermission, Long> {

    @Modifying
    @Query("update RolePermission o set o.remove = true where o.role.id = :roleId and o.remove = false ")
    void deleteByRoleId(@Param("roleId") Long roleId);

    @Query("select o.permission from RolePermission o where o.role.id = :roleId and o.remove = false")
    List<Permission> findPermissionByRoleId(@Param("roleId") Long roleId);

}
